package com.atguigu.spring5.testdemo;

import com.atguigu.spring5.User;
import com.atguigu.spring5.bean.Emp;
import com.atguigu.spring5.service.UserService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * IOC入门实例
 */
public class TestBean {

    @Test
    public void testAdd() {
        //1.加载Spring的配置文件
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean2.xml");

        //2.获取配置文件创建的对象
        UserService userService = applicationContext.getBean("userService", UserService.class);

        userService.add();

    }

    @Test
    public void testBean() {

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean3.xml");

        Emp emp = applicationContext.getBean("emp", Emp.class);

        emp.add();

    }


    @Test
    public void testAddBean() {

        //1.加载spring配置文件
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean1.xml");

        //2.获取配置创建的对象
        User user = applicationContext.getBean("user", User.class);

        System.out.println(user);
        user.add();
    }




}
